package com.igeekhome.controller;

import com.igeekhome.mapper.WWaybillMapper;
import com.igeekhome.mapper.WWaybillRuleMapper;
import com.igeekhome.pojo.DNetwork;
import com.igeekhome.pojo.WWaybillRule;
import com.igeekhome.pojo.WWaybillRuleExample;
import com.igeekhome.service.INetworkService;
import com.igeekhome.service.IWaybillRulesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author 陈维豪
 */
@RequestMapping("/page/orderNumberList")
@Controller
public class OrderNumberListController {

    @Autowired
    private INetworkService networkService;

    @Autowired
    private WWaybillRuleMapper waybillRuleMapper;

    @Value("${WAYBILL_RULE_Id}")
    private Integer WAYBILL_RULE_Id;

    @RequestMapping("")
    public String list(Model model){
        List<DNetwork> networks = networkService.selectAll();
        model.addAttribute("networks",networks);
        return "pages/data/oddManage/oddList";
    }

    @RequestMapping("/add")
    public String add(Model model){
        List<DNetwork> networks = networkService.selectAll();
        WWaybillRuleExample we = new WWaybillRuleExample();
        we.createCriteria().andUsageStatusEqualTo("1").andTypeIdEqualTo(WAYBILL_RULE_Id);
        List<WWaybillRule> wWaybillRules = waybillRuleMapper.selectByExample(we);
        WWaybillRule wWaybillRule = wWaybillRules.get(0);
        Integer maxWayBillId = wWaybillRule.getMaxWayBillId();
        model.addAttribute("maxWayBillId",maxWayBillId);
        model.addAttribute("networks",networks);
        return "/pages/data/oddManage/oddListAdd";
    }

    @RequestMapping("/edit")
    public String edit(){
        return "/pages/data/oddManage/oddListEdit";
    }

}
